import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "material-icons/iconfont/material-icons.css";
import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

Vue.config.productionTip = false;

// echarts.registerMap('china', geoJson);

import axios from "axios"; //引入axios
//用axios的拦截器,加上请求头
axios.interceptors.request.use((config) => {
  let jwt = localStorage.getItem("token");
  if (jwt) {
    config.headers.token = jwt;
  }
  return config;
});

axios.interceptors.response.use(
  (response) => {
    if (response.status == 403) {
      // this.$router.push({ path: '/'});
      router.push({ path: "/" });
    }
    return response;
  },
  (error) => {
    return Promise.reject(error);
  }
);

Vue.prototype.$axios = axios; //把axios配置全局的变量，变量名是$axios

import BaiduMap from "vue-baidu-map";
Vue.use(BaiduMap, {
  ak: "BGBp2gB1Lnd3uUcjy36NCJRByt6ZxQ3e",
});

Vue.use(ElementUI);

new Vue({
  router,
  render: (h) => h(App),
}).$mount("#app");
